<?php

namespace qore_base\util\collections;
use \qore\base\Component;

/**
 * @author Samuel Nogueira <samuel.nogueira.dev@gmail.com>
 */
abstract class Collection extends Component implements \IteratorAggregate, \Countable {

	/**
	 * Constructor.
	 * Initializes the list with an array or an iterable object.
	 * @param array $data the intial data. Default is null, meaning no initialization.
	 */
	public function __construct($data=null) {
		$this->addAll($data);
	}

	/**
	 * Returns the number of items in the list.
	 * This method is required by Countable interface.
	 * @return integer number of items in the list.
	 */
	public function count() {
		return $this->getCount();
	}
	
	/**
	 * Returns an iterator for traversing the items in the collection.
	 * This method is required by the interface IteratorAggregate.
	 * @return \qore\util\collections\Iterator an iterator for traversing the items in the list.
	 */
	abstract public function getIterator();
	
	/**
	 * Returns the number of items in the list.
	 * @return integer the number of items in the list
	 */
	abstract public function getCount();

	/**
	 * Removes all items in the collection.
	 */
	abstract public function clear();

	/**
	 * @param mixed $item the item
	 * @return boolean whether the collection contains the item
	 */
	abstract public function contains($item);

	/**
	 * @return array the list of items in collection
	 */
	abstract public function toArray();

	/**
	 * Adds all items to this collection.
	 * @param mixed Items to add.
	 * @throws Exception If data is not null and neither an array nor an iterator.
	 */
	abstract public function addAll($data);
}

